package za.org.meraka.cair.ontorepair;

import java.util.Set;
import java.util.HashSet;

public class Node<T> {
 	
	public Set<T> prev,data;
    public Set<T>[] paths;
    public Set<Node<T>> children;
    public Node<T> parent;
    public int leaf;    
 
    public Node() {    	
        super();
        leaf = 0;
        parent = null;        
    }
  
    public Node(Set<T> d, Set<T> p, Node<T> par) {
        this();        
        setData(d);
        setPrev(p);
        setPaths();
        leaf = 0;
        parent = par;
    }
     
    public void setPaths(){
    	paths = new HashSet[data.size()];
    	T[] dataArr = (T[])data.toArray((T[])new Object[data.size()]);
    	for (int i = 0; i < data.size(); i++){
    		paths[i] = new HashSet<T>();
    		paths[i].add(dataArr[i]);
    		paths[i].addAll(prev);    		
    	}
    }
    
    public void addChild(Node<T> child) {
        if (children == null) {
            children = new HashSet<Node<T>>();
        }
        children.add(child);
    }     
   
    public Set<Node<T>> getChildren(){return children;}
    
    public Set<T> getData() {return this.data;}
 
    public void setData(Set<T> myData) {this.data = new HashSet<T>();this.data.addAll(myData);}
       
    public Set<T> getPath() {return this.prev;}
 
    public void setPrev(Set<T> myPrev) {this.prev = new HashSet<T>();this.prev.addAll(myPrev);}  
    
    public Set<T> getPrev(T mPrev){
    	Set<T> result = new HashSet<T>();
    	result.addAll(this.prev);
    	result.add(mPrev);
    	return result;
    }
    
    public void setLeaf(int n) {leaf = n;}    
}
